# !/usr/bin/env python
import os

from app import create_app
from flask.ext.script import Manager

from flask.ext.sqlalchemy import SQLAlchemy
from flask.ext.httpauth import HTTPBasicAuth


app = create_app(os.getenv('FLASK_CONFIG') or 'default')
app.debug = True
DEBUG = True

basedir = os.path.abspath(os.path.dirname(__file__))

# flask-sqlalchemy
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'db.sqlite')
app.config.setdefault('SQLALCHEMY_TRACK_MODIFICATIONS', True)
app.config.setdefault('SQLALCHEMY_ECHO', True)
app.config.setdefault('SQLALCHEMY_RECORD_QUERIES', True)
# app.config.setdefault('SQLALCHEMY_POOL_SIZE', 5)
# app.config.setdefault('SQLALCHEMY_POOL_TIMEOUT', 10)
db = SQLAlchemy(app)



# flask-httpauth
auth = HTTPBasicAuth()

manager = Manager(app)

@app.after_request
def after_request(response):
    response.headers.add('Access-Control-Allow-Origin', '*')
    response.headers.add('Access-Control-Allow-Headers', 'Content-Type,Authorization')
    response.headers.add('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE')
    return response


if __name__ == '__main__':
    manager.run()
